﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using com.dz.components;
using com.dz.common;
namespace com.dz.web
{
    public partial class AjaxUtil : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string opName = Request["opName"];

            string result = string.Empty;
            
            string procName = Request["procName"];
 
          
            switch (opName)
            {
                case "ExcuteScript":
                    result = this.ToJSON(PageUtil.ExcuteScript(procName, Request["script"]));
                    break;
                case "GetDataList":
                    int t_page_index = 0;
                    if (!int.TryParse(Request["pageIndex"], out t_page_index))
                        t_page_index = 1;
                    int t_page_size=15;
                    if (!int.TryParse(Request["pageSize"], out t_page_size))
                        t_page_size = 15;
                    int t_total_count = 0;
                    if (!int.TryParse(Request["totalCount"], out t_total_count))
                        t_total_count = 0;
                    if (procName.ToLower().Equals("book"))
                    {
                        result = ToJSON(PageUtil.GetChannelBook(t_page_index, t_page_size, t_total_count, Request["strWhere"]));
                    }
                    else
                    {
                        result = ToJSON(PageUtil.GetList(t_page_index, t_page_size, t_total_count, Request["strWhere"]));
                    }
                    break;
            }
            
            Response.Clear();
            Response.Write(result);
            Response.End();
        }

   

        private string ToJSON(string singleData)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("{value:");
            sb.Append("\"");
            sb.Append(singleData).Append("\"").Append("}");

            return sb.ToString();
        }
    }
}
